<?php
/**
 * 用户接口
 * Created by PhpStorm.
 * User: soshow
 * Date: 17/3/7
 * Time: 下午4:50
 */
class userControl extends Control{

    private $PASSWDKEY;

    public function __construct(){
        parent::__construct();
        $this->PASSWDKEY = '@soshow#';
    }

    /**
     * 用户登录(客户端)
     */
    public function loginOp(){
        $this->isPost();
        $member_mobile = $_POST['mobile'];
        $password = $_POST['password'];
        $device_id = $_POST['device_id']; //设备Id
        if(empty($member_mobile) || empty($password) || empty($device_id)){
            $this->response('',4003,'参数不能为空');
        }
        $password = md5($password.PASSWDKEY);
        $member = Model('member');
        $memberInfo = $member->getMemberInfo(array('member_mobile'=>$member_mobile,'member_password'=>$password));
        if(empty($memberInfo)) {
            $this->response('', 4000, '账号或者密码错误');
        }else if($memberInfo['member_type'] == 20){
            $this->response('', 4000, '你还不是移动车司机!');
        }else if($memberInfo['member_state'] == 0){
            $this->response('', 4000, '您的账号被禁用了,请联系管理员');
        }else{
            $time = time();
            $token = md5($member_mobile.'soshow'.$time.'#$%'.rand(1000,9999));
            $result = $member->updateMember(array('member_id'=>$memberInfo['member_id']), array('token'=>$token,'login_time'=>$time));
            if($result){
                $memberInfo['token']      = $token;
                $memberInfo['login_time'] = $time;
                unset($memberInfo['member_password']);
                unset($memberInfo['wx_openid']);
                unset($memberInfo['wx_userinfo']);
                $this->response($memberInfo,2000,'登录成功');
            }else{
                $this->response('',5000);
            }
        }
    }
    
}
?>